#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

class Solution {
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
        int n = intervals.size();
        vector<vector<int>> ret;
        sort(intervals.begin(), intervals.end());
        int b = intervals[0][0], e = intervals[0][1];
        for (int i = 1; i < n; i++)
        {
            if (intervals[i][0] <= e) e = max(e, intervals[i][1]);
            else
            {
                ret.push_back({ b,e });
                b = intervals[i][0];
                e = intervals[i][1];
            }
        }
        ret.push_back({ b,e });
        return ret;
    }
};
int main()
{
    vector<vector<int>>vv({ {5, 6},{1, 2},{2, 4},{5, 5},{5, 5},{3, 3} });
    Solution s;
    vector<vector<int>>ret = s.merge(vv);

    return 0;
}